﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.Statistics;
using DevExpress.XtraEditors.Controls;
using MINERP.MODEL.FoundationModel;
using MINERP.COM;
using MINERP.ComControls.Extension;

namespace MINERP.Statistics.Forms
{
    public partial class FrmBoardStat : Form
    {
        public FrmBoardStat()
        {
            InitializeComponent();
            gridView.ShowRowIndicator(50);
        }
        BoardStatBLL _bll = new BoardStatBLL();
        private void FrmBoardStat_Load(object sender, EventArgs e)
        {
            dtStart.DateTime = DateTime.Now;
            dtEnd.DateTime = DateTime.Now;
            initForm();
        }
        private static FrmBoardStat _instance;
        public static FrmBoardStat GetInstance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                {
                    _instance = new FrmBoardStat();
                }
                return _instance;
            }
        }

        void initForm()
        {
            comboxPrinter.Properties.DataSource = _bll.GetPrinterXray();
            comboxPrinter.Properties.DisplayMember = "PName";
            comboxPrinter.Properties.ValueMember = "PrinterID";

            comboxPaperType.Properties.DataSource = _bll.GetAllPaperType();
            comboxPaperType.Properties.DisplayMember = "Name";
            comboxPaperType.Properties.ValueMember = "PaperTypeID";

            comboxUsers.Properties.DataSource = _bll.GetUserList();
            comboxUsers.Properties.DisplayMember = "UserName";
            comboxUsers.Properties.ValueMember = "UserID";
        }
        string Printid = "";
        string PaperTypeId = "";
        string UserId = "";
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                foreach (CheckedListBoxItem item in comboxPrinter.Properties.Items)
                {
                    if (item.CheckState == CheckState.Checked)
                    {
                        Printid += (int)item.Value + ",";
                    }
                }

                foreach (CheckedListBoxItem item in comboxPaperType.Properties.Items)
                {
                    if (item.CheckState == CheckState.Checked)
                    {
                        PaperTypeId += (int)item.Value + ",";
                    }
                }
                foreach (CheckedListBoxItem item in comboxUsers.Properties.Items)
                {
                    if (item.CheckState == CheckState.Checked)
                    {
                        UserId += (int)item.Value + ",";
                    }
                }
                DateTime stTime = dtStart.DateTime;
                DateTime endTime = dtEnd.DateTime;
                DataTable table = _bll.GetData(Printid.TrimEnd(','), PaperTypeId.TrimEnd(','), UserId.Trim(','), stTime, endTime);

                gridControl.DataSource = table;
            }
            catch
            {
                MessageBox.Show("获取数据失败，请查看服务器是否启动","提醒",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            finally
            {
                this.Cursor = Cursors.Default; ;
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            gridControl.ExportToExcel(this, "输出设备统计" + DateTime.Now.ToString("yyyyMMddHHmmss"));
            //DevGridViewExport.ExportToExcel("输出设备统计" + DateTime.Now.ToString("yyyyMMddHHmmss"), gridView);
        }
    }
}
